package cn.lycode.common.event;

import cn.lycode.common.core.domain.AjaxResult;
import cn.lycode.common.enums.ErrorEnum;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Data
public class SessionChangeMeta {

    private List<?> roleFlagList;  //变动的角色
    private List<?> userIdList;  //变动的用户


    public static SessionChangeMeta roleList(List<?> roleFlags) {
        ErrorEnum.PARAM_NULL.assertNotNull(roleFlags);
        SessionChangeMeta sessionChangeMeta = new SessionChangeMeta();
        sessionChangeMeta.setRoleFlagList(roleFlags);
        return sessionChangeMeta;
    }

    public static SessionChangeMeta role(Object roleFlag) {
        SessionChangeMeta sessionChangeMeta = new SessionChangeMeta();
        if (roleFlag != null) {
            sessionChangeMeta.setRoleFlagList(Collections.singletonList(roleFlag));
        }
        return sessionChangeMeta;
    }


    public static SessionChangeMeta userList(List<?> userFlags) {
        ErrorEnum.PARAM_NULL.assertNotNull(userFlags);
        SessionChangeMeta sessionChangeMeta = new SessionChangeMeta();
        sessionChangeMeta.setUserIdList(userFlags);
        return sessionChangeMeta;
    }

    public static SessionChangeMeta user(Object userFlag) {
        SessionChangeMeta sessionChangeMeta = new SessionChangeMeta();
        if (userFlag != null) {
            sessionChangeMeta.setUserIdList(Collections.singletonList(userFlag));
        }
        return sessionChangeMeta;
    }

    private SessionChangeMeta(){
        roleFlagList = new ArrayList<>();
        userIdList = new ArrayList<>();
    }
}
